﻿Imports Microsoft.Owin.Security
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Linq

Public Class OpenAuthProvider
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If IsPostBack Then
            Dim provider = Request.Form("provider")
            If provider Is Nothing Then
                Return
            End If
            ' Request a redirect to the external login provider
            Context.Challenge(New String() {provider}, New AuthenticationExtra() With { _
        .RedirectUrl = "/Account/RegisterExternalLogin?providerName=" + provider _
    })
            Response.StatusCode = 401
            Response.[End]()
        End If
    End Sub

    Public Property ReturnUrl() As String
        Get
            Return m_ReturnUrl
        End Get
        Set(value As String)
            m_ReturnUrl = value
        End Set
    End Property
    Private m_ReturnUrl As String

    Public Function GetProviderNames() As IEnumerable(Of String)
        Return Context.GetExternalAuthenticationTypes().[Select](Function(t) t.Properties("AuthenticationType").ToString())
    End Function
End Class